import * as index from '@/api/index.js'
import {
	baseURL
} from '../../common/config.js'
export default {
	data() {
		return {
			form: {},
			loading: false,
			deposit: '',
			typeList: [],
			typeIndex: -1,
			text: '',
			menuButtonInfo: uni.getMenuButtonBoundingClientRect(),
			background: 'rgba(255, 132, 0, 0)'
		}
	},

	onShow() {

	},
	onLoad(option) {
		this.getOrderDetail(option.id)
	},
	onPageScroll(e) {
		if (e.scrollTop < 150) {
			this.background = `rgba(255, 132, 0, ${e.scrollTop/150})`
		} else {
			this.background = 'rgba(255, 132, 0, 1)'
		}
	},
	methods: {
		getOrderDetail(id) {
			index.getOrderDetail({
				order_id: id
			}).then(res => {
				this.form = res.data
				this.loading = true
			})
		},
		goPay(item) {
			let that = this
			index.goPay({
				order_id: that.form.id
			}).then(res => {
				uni.requestPayment({
					provider: 'wxpay',
					timeStamp: res.data.timeStamp,
					nonceStr: res.data.nonceStr,
					package: res.data.package,
					signType: res.data.signType,
					paySign: res.data.paySign,
					success: res => {
						that.$tools.toast('支付成功')
						uni.$emit('update', {
							msg: '页面更新'
						})
						that.back()
					},
					fail: err => {
						that.$tools.toast('支付失败')
					}
				});
			})
		},
		cancelOrder(item) {
			let that = this
			uni.showModal({
				title: '提示',
				content: '是否确定取消订单?订单取消后不可撤销。',
				success: function(res) {
					if (res.confirm) {
						index.cancelOrder({
							order_id: that.form.id
						}).then(res => {
							uni.$emit('update', {
								msg: '页面更新'
							})
							that.back()
						})
					} else if (res.cancel) {
					}
				}
			});

		},
		back() {
			this.$tools.back(1)
		},

	}
}